﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

/// <summary>
/// Descripción breve de HH_Toolkit
/// </summary>
public abstract class HH_Toolkit
{
    public static string TextoTATTEM(DateTime dtETA, DateTime dtETD, int Horas)
    {
        string strTexto;
        TimeSpan tsHoraTAT = dtETD - dtETA;
        TimeSpan tsHoraTEM = tsHoraTAT.Subtract(new TimeSpan(Horas,0,0));

        strTexto = "TAT: " + tsHoraTAT.ToString() + "<br />TEM: " + tsHoraTEM.ToString();
        return strTexto;
    }

    public static DateTime ConvertirDateTime(string CadenaFechaFormat, string CadenaHoraFormat, string CadenaDTFormat)
    {
        string strDTHoraETA;     

        if (CadenaFechaFormat.Length > 0)
        {
            strDTHoraETA = CadenaFechaFormat;
            if (CadenaHoraFormat.Length > 0)
                strDTHoraETA += " " + CadenaHoraFormat;
            else
                strDTHoraETA += " " + "00:00";
        }
        else
        {
            if (CadenaDTFormat.Length > 18)
                strDTHoraETA = CadenaDTFormat;
            else
                strDTHoraETA = "01/01/1900 00:00";
        }
        return Convert.ToDateTime(strDTHoraETA);
    }

    public static string AsegurarFormatoMatricula(string strMatAvion)
    {
        //string strMatAvion;
        //strMatAvion = txtMatAvi.Text;

        if (strMatAvion[2] != '-')
        {
            strMatAvion = StringConstantes.PREF_AVION + strMatAvion;
        }
        return strMatAvion.ToUpper();
    }

    public static string PresentarMatriculaSinPrefCC(string strMatAvion)
    {
        string SubCadMat = strMatAvion;
        if(strMatAvion.Length > 3)
            SubCadMat = strMatAvion.Substring(3);

        return SubCadMat.Trim();

    }

    public static bool ValidarExistenciaMat(string strMatAvi)
    {
        bool returnValue = false;
        HHo_Negocio.GestorPMS oGesPms;

        oGesPms = new HHo_Negocio.GestorPMS();

        //TODO - Si no existe la flota del avion se debe restringir
        try
        {
            if (oGesPms.VerificarExisteMat(strMatAvi))
                returnValue = true;
        }
        catch
        {
            throw;
        }
        return returnValue;
    }
}
